package com.cw.base.common.dispatch.task.facade.ref.converter;

import java.util.UUID;

import com.cw.base.common.dispatch.pojo.Task;
import com.cw.base.common.dispatch.task.facade.pojo.request.TaskRequest;

/**
 * Created on 15/11/9.
 *
 * @author zhangcheng
 */
public class TaskRequestConverter {

    public static Task convert(TaskRequest taskRequest) {
        return Task.builder()
            .baseRequest(taskRequest.getRequest())
            .baseUserRequest(taskRequest.getBaseUserRequest())
            .normalTask(taskRequest.getNormalTask())
            .targetMethod(taskRequest.getTargetMethod())
            .targetObject(taskRequest.getTargetObject())
            .parameters(taskRequest.getParameters())
            .targetClass(taskRequest.getTargetClass())
            .constructorParameters(taskRequest.getConstructorParameters())
            .taskCallBack(taskRequest.getTaskCallBack())
            .errorLoop(taskRequest.isErrorLoop())
            .apartExecTime(taskRequest.getApartExecTime())
            .delayExecTime(taskRequest.getDelayExecTime())
            .execNum(taskRequest.getExecNum())
            .errorTaskCallBack(taskRequest.getErrorTaskCallBack())
            .loopCondition(taskRequest.getLoopCondition())
            .uuid(UUID.randomUUID()
                .toString())
            .callBackConstructorParameters(taskRequest.getCallBackConstructorParameters())
            .taskCallBackClass(taskRequest.getTaskCallBackClass())
            .errorTaskCallBackClass(taskRequest.getErrorTaskCallBackClass())
            .taskCallBackMethod(taskRequest.getTaskCallBackMethod())
            .errorTaskCallBackMethod(taskRequest.getErrorTaskCallBackMethod())
            .businessParam(taskRequest.getBusinessParam())
            .build();
    }

}
